/*
 * Copyright (c) 2016-2021, Hangzhou Qulian Technology Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _LOG_H_
#define _LOG_H_

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include "ql_type.h"

// Maximum length of log content
#define LOG_MAX_SIZE 1024

// Enumerate log types
typedef enum { LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR } ql_log_level;

// Define log silent state
#define LOG_QUIET_TRUE   1
#define LOG_QUIET_FALSE  0

// Callback function of <print> and <time>
typedef void (*PRINT_LOG_CALLBACK)(char *content);
typedef void (*GET_TIME_CALLBACK)(char *time, int size);

// The definition of the logs method, used to format the output content
ql_void_t logs(ql_log_level level, const char *file, int line, const char *fmt, ...);

// -----------------------
// User Function
// -----------------------
// If you don’t need to use colors or titles, cancel the following definitions
#define LOG_USE_COLOR
#define LOG_USE_TITLE

// Methods for printing logs of different levels
#define log_debug(...) logs(LOG_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
#define log_info(...)  logs(LOG_INFO,  __FILE__, __LINE__, __VA_ARGS__)
#define log_warn(...)  logs(LOG_WARN,  __FILE__, __LINE__, __VA_ARGS__)
#define log_error(...) logs(LOG_ERROR, __FILE__, __LINE__, __VA_ARGS__)

// Set the lowest printing level
ql_void_t LogSetLevel(ql_log_level level);
// Set whether silent mode is required
ql_void_t LogSetQuiet(ql_bool_t   enable);
// Set the callback function for printing
ql_void_t SetPrintLogCallback(PRINT_LOG_CALLBACK callback);
// Set the callback function for getting time
ql_void_t SetGetTimeCallback(GET_TIME_CALLBACK callback);

#endif
